<template>
  <div class="list-container">
    <vab-query-form>
      <el-form
        ref="form"
        :model="queryForm"
        :inline="true"
        @submit.native.prevent
      >
        <el-form-item>
          <el-select
            v-model="queryForm.queryBean.type"
            placeholder="类别筛选"
            @change="changeSelect"
          >
            <el-option label="项目大事记" value="1"></el-option>
            <el-option label="房屋节点" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-select
            v-model.trim="queryForm.queryBean.statusList"
            multiple
            collapse-tags
            :style="{ width: '100%' }"
            placeholder="请选择审核状态"
            clearable
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button
            icon="el-icon-search"
            type="primary"
            native-type="submit"
            @click="handleQuery"
          >
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </vab-query-form>
    <el-table
      ref="tableSort"
      v-loading="listLoading"
      :data="list"
      style="width: 100%"
      :element-loading-text="elementLoadingText"
      :height="height"
    >
      <el-table-column
        v-if="
          queryForm.queryBean.type == 1 ||
          queryForm.queryBean.type == '项目大事记'
        "
        show-overflow-tooltip
        label="地产名称"
        prop="propertyName"
        width="120"
      ></el-table-column>
      <el-table-column
        v-if="queryForm.queryBean.type == 2"
        show-overflow-tooltip
        label="地产名称"
        prop="estateName"
        width="120"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="项目名称"
        prop="projectName"
        width="120"
      ></el-table-column>
      <el-table-column
        v-if="queryForm.queryBean.type == 2"
        show-overflow-tooltip
        label="目标位置"
        width="200"
      >
        <template #default="{ row }">
          {{ row.estateLocation ? row.estateLocation : row.partName }}
        </template>
      </el-table-column>
      <!-- <el-table-column
        show-overflow-tooltip
        label="ID"
        prop="eventId"
        width="150"
      ></el-table-column> -->

      <el-table-column
        show-overflow-tooltip
        label="问题描述"
        prop="feedBack"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="审核状态"
        prop="eventStatus"
        width="100"
      >
        <template #default="{ row }">
          <el-tag
            size="small"
            :type="
              row.eventStatus == 3
                ? 'success'
                : row.eventStatus == 4
                ? 'danger'
                : row.eventStatus == 1
                ? 'info'
                : 'warning'
            "
          >
            {{ getValue(row.eventStatus) }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="开始时间"
        prop="startTime"
        width="160"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        label="结束时间"
        prop="endTime"
        width="160"
      ></el-table-column>
      <el-table-column show-overflow-tooltip label="审核" width="200">
        <template #default="{ row }">
          <el-button type="primary" @click="handleEdit(row)">详情</el-button>
          <!-- <el-button
            v-if="row.eventStatus == 2"
            type="primary"
            size="mini"
            @click="handlePass(row)"
          >
            通 过
          </el-button>
          <el-button
            v-if="row.eventStatus == 2"
            type="danger"
            size="mini"
            @click="handleRefuse(row)"
          >
            不通过
          </el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :background="background"
      :current-page="queryForm.queryBean.pageNum"
      :layout="layout"
      :page-size="queryForm.queryBean.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
    <check-note ref="check" @fetch-data="fetchData"></check-note>
  </div>
</template>
<script>
  import { getEventPageList, modSingleItem } from '@/api/houseNode'
  import _ from 'lodash'
  import { data } from 'vue-echarts'
  import CheckNote from './components/CheckNote.vue'
  export default {
    name: 'Note',
    components: { CheckNote },
    data() {
      return {
        options: [
          {
            value: 1,
            label: '待上传',
          },
          {
            value: 2,
            label: '未审核',
          },
          {
            value: 3,
            label: '已通过',
          },
          {
            value: 4,
            label: '未通过',
          },
        ],
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        background: true,
        elementLoadingText: '正在加载...',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          queryBean: {
            type: '项目大事记',
            statusList: [4, 1, 2, 3],
          },
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      this.fetchData()
    },
    mounted() {},
    methods: {
      changeSelect(value) {
        console.log(value)
        this.fetchData()
      },
      handleEdit(row) {
        if (row) {
          this.$refs['check'].showEdit(row)
        } else {
          this.$refs['check'].showEdit()
        }
      },
      getValue(value) {
        switch (value) {
          case 1:
            return '待上传'
          case 2:
            return '未审核'
          case 3:
            return '已通过'
          case 4:
            return '未通过'
        }
      },
      async handlePass(row) {
        let temp = {
          eventId: row.eventId,
          eventStatus: 3,
        }
        const { data } = await modSingleItem(temp)
        this.fetchData()
      },
      async handleRefuse(row) {
        let temp = {
          eventId: row.eventId,
          eventStatus: 4,
        }
        const { data } = await modSingleItem(temp)
        this.fetchData()
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      handleQuery() {
        this.queryForm.pageNum = 1
        this.fetchData()
      },
      async fetchData() {
        let temp = _.cloneDeep(this.queryForm)
        if (this.queryForm.queryBean.type == '项目大事记') {
          temp.queryBean.type = 1
        } else {
          temp.queryBean.type = Number(this.queryForm.queryBean.type)
        }
        this.listLoading = true
        temp.queryBean.rootPartId = '1'
        const { data } = await getEventPageList(temp)
        const { body: result } = data
        this.list = result.data
        this.total = result.totalSize
        this.$baseNotify('进度数据获取完毕！', '成功', 'success', 'top-right')
        setTimeout(() => {
          this.listLoading = false
        }, 500)
      },
    },
  }
</script>
